#include "Setting_General.h"

#include <QStackedWidget>
#include <QApplication>
#include <QAbstractItemView>

namespace UserManagementSystem {


Setting_General::Setting_General(QWidget *parent)
    :QWidget(parent)
{
    qDebug()<<__FUNCTION__;

    m_mainLayout=new QVBoxLayout(this);

    m_langLabel=new QLabel(tr("语言"),this);

    m_toothNumLabel=new QLabel(tr("牙齿编号"),this);

    m_wirelessLabel=new QLabel(tr("无线设备连接助手"));

    m_wireTip=new QLabel(tr("了解如何连接无线设备"),nullptr);
    m_chooseLanCombobox=new QComboBox();

    m_generalNumberSystemBtn=new QRadioButton(tr("通用编号系统"));

    m_FDIMark=new QRadioButton(tr("FDI标记法"));

    m_btnsGroup=new QButtonGroup();

    m_btnsLayout=new QHBoxLayout();

    m_rightArrowBtn=new QPushButton();

    m_labelsLayout=new QVBoxLayout();

    m_wirelessLayout=new QHBoxLayout();




    InitDefaultLayout();
    AddItems();

    connect(m_chooseLanCombobox,&QComboBox::currentTextChanged,this,&Setting_General::On_language_changed);
}

void Setting_General::On_language_changed()
{
    qDebug()<<"当前选择的语言为："<<m_chooseLanCombobox->currentText();
}

void Setting_General::InitDefaultLayout()
{
    m_btnsGroup->addButton(m_generalNumberSystemBtn);
    m_btnsGroup->addButton(m_FDIMark);

    m_btnsLayout->addWidget(m_generalNumberSystemBtn);
    m_btnsLayout->addWidget(m_FDIMark);
    m_btnsLayout->addStretch(1);

    m_labelsLayout->addWidget(m_wirelessLabel);
    m_labelsLayout->addWidget(m_wireTip);


    m_wirelessLayout->addLayout(m_labelsLayout);
    m_wirelessLayout->addWidget(m_rightArrowBtn);


    m_mainLayout->addWidget(m_langLabel);
    m_mainLayout->addWidget(m_chooseLanCombobox);
    m_mainLayout->addSpacing(10);
    m_mainLayout->addWidget(m_toothNumLabel);
    m_mainLayout->addLayout(m_btnsLayout);
    m_mainLayout->addSpacing(10);
    m_mainLayout->addLayout(m_wirelessLayout);
    m_mainLayout->addStretch(1);

    m_mainLayout->setContentsMargins(10,10,10,10);
    m_mainLayout->setSpacing(10);//控件内部间距同意设置为10
    InitDefaultStyle();

}

void Setting_General::InitDefaultStyle()
{
    QString label_style=(R"(
        font-size:9pt;color: black; font-weight: bold;
    )");

    m_langLabel->setStyleSheet(label_style);
    m_toothNumLabel->setStyleSheet(label_style);
    m_wirelessLabel->setStyleSheet(label_style);

    QString arrow_icon_path=QApplication::applicationDirPath()+"/res/PatientManager/lower_arrow.png";

    QString Combobox_style=QString(R"(
    QComboBox {
        padding-right: 30px;
        padding-left: 10px;
        height: 30px;
        border-radius: 5px;
        border: 1px solid #6d90d0;
        background-color:#f7f9fb;
    }
    QComboBox::drop-down {
        width: 30px;
        background-color:white;
        color: black;
        border-radius: 5px;
    }
    QComboBox::down-arrow {
        image:url(%1);
        width: 14px;
        height: 14px;
    }
    QComboBox QAbstractItemView {
        outline: none;  /* 取消焦点虚线框 */
        border: none;   /* 如果有边框，也去掉 */
    }
    QComboBox QAbstractItemView::item {
        background-color: white;
        height: 30px;
        border-radius:5px;
        color: black;
    }
    QComboBox QAbstractItemView::item:hover {
        background-color: #4672c4;
        color: white;
        border-radius:5px;
    }
    QComboBox QAbstractItemView QScrollBar:vertical {
        background: transparent;
        width: 2px;
        margin: 0px 0px 0px 0px;
    }
    QComboBox QAbstractItemView QScrollBar::handle:vertical {
        background: gray;
        height: 3px;
        width: 2px;
        border-radius: 2px;
    }
    QComboBox QAbstractItemView QScrollBar::sub-line, QScrollBar::add-line,
    QScrollBar::up-arrow,QScrollBar::down-arrow:vertical {
        height: 0px;
    }


)").arg(arrow_icon_path);

    m_chooseLanCombobox->setStyleSheet(Combobox_style);
    m_chooseLanCombobox->view()->setFocusPolicy(Qt::NoFocus);

    QString right_arrow_path=QApplication::applicationDirPath()+"/res/PatientManager/right_arrow.png";

    m_rightArrowBtn->setFixedSize(30,30);
    m_rightArrowBtn->setStyleSheet("border:none;");
    m_rightArrowBtn->setIcon(QIcon(right_arrow_path));

}

void Setting_General::AddItems()
{
    m_chooseLanCombobox->addItem(tr("简体中文"));
    m_chooseLanCombobox->addItem(tr("English-US"));
    m_chooseLanCombobox->addItem(tr("English-EU"));
    m_chooseLanCombobox->addItem(tr("繁体中文"));
    m_chooseLanCombobox->addItem(tr("俄文"));
    m_chooseLanCombobox->addItem(tr("韩文"));

    m_chooseLanCombobox->addItem(tr("日文"));
    m_chooseLanCombobox->addItem(tr("希腊文"));
    m_chooseLanCombobox->addItem(tr("埃塞俄比亚"));
    m_chooseLanCombobox->addItem(tr("捷克语"));
    m_chooseLanCombobox->addItem(tr("俄文"));
    m_chooseLanCombobox->addItem(tr("韩文"));

}

}
